
package com.be.beadmin.system.impl.ProjectDesignServiceImpl;

import com.be.beadmin.basicData.dto.output.UserEx;
import com.be.beadmin.basicData.service.UserService;
import com.be.beadmin.common.entity.PageEntity;
import com.be.beadmin.common.exception.BeadminException;
import com.be.beadmin.design.dto.output.ProductDesignEx;
import com.be.beadmin.design.entity.BatchProductDesign;
import com.be.beadmin.design.entity.ProductDrawingInfo;
import com.be.beadmin.design.entity.StandFileInfo;
import com.be.beadmin.design.entity.StandProduct;
import com.be.beadmin.design.repository.ProductDrawingInfoRepository;
import com.be.beadmin.design.repository.StandFileInfoRepository;
import com.be.beadmin.design.repository.StandProductRepository;
import com.be.beadmin.design.service.ProductBomOverviewService;
import com.be.beadmin.design.service.ProductDrawingInfoService;
import com.be.beadmin.project.Util.MinioUtil;
import com.be.beadmin.project.dto.output.BatchProductEx;
import com.be.beadmin.project.entity.*;
import com.be.beadmin.project.repository.*;
import com.be.beadmin.project.service.BatchPlanService;
import com.be.beadmin.project.service.BatchProductService;
import com.be.beadmin.service.service.DictDataService;
import com.be.beadmin.service.util.DateUtil;
import com.be.beadmin.system.service.ProjectDesignSevice.BatchProductPdService;
import lombok.RequiredArgsConstructor;
import lombok.SneakyThrows;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import javax.transaction.Transactional;
import java.util.Date;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.function.Function;

/**
 * @author zjm
 * @description 服务实现
 * @date 2023-02-13
 **/
@Service
@RequiredArgsConstructor
public class BatchProductPdServiceImpl implements BatchProductPdService {
    @Autowired
    private ThreadPoolExecutor threadPoolExecutor;
    @Autowired
    private BatchProductRepository batchProductRepository;

    @Autowired
    private BatchPlanRepository batchPlanRepository;
    @Autowired
    private BatchPlanService batchPlanService;
    @Autowired
    private MasterPlanRepository masterPlanRepository;
    @Autowired
    private StandProductRepository standProductRepository;
    @Autowired
    private ProductBomOverviewService productBomOverviewService;
    @Autowired
    private StandFileInfoRepository standFileInfoRepository;

    @Autowired
    private BatchProductService batchProductService;
    @Autowired
    private ProductDrawingInfoRepository productDrawingInfoRepository;
    @Autowired
    private TeamInfoRepository teamInfoRepository;
    @Autowired
    private UserService userService;
    @Autowired
    private MinioUtil minioUtil;

    @Autowired
    private InfoRepository infoRepository;
    @Autowired
    private ProductDrawingInfoService productDrawingInfoService;


    @Autowired
    private DictDataService dictDataService;
    /**
     * 用productInfo更新批次柜体信息
     *
     * @param productInfo
     */
    @Override
    public void updateBatchProduct(ProductInfo productInfo) {
        // 找到柜体
        BatchProduct batchProduct = batchProductRepository.findBatchProductByProductCodeAndDelete(productInfo.getProductCode(), 0);
//        batchProduct.setInfoId(productInfo.getInfoId());
//        batchProduct.setProductCode(productInfo.getProductCode());
        // 设置柜体类型
        batchProduct.setProductType(productInfo.getProductType());
//        batchProduct.setBatchPlanId("-1");
        batchProduct.setIsStandard(productInfo.getIsStandard());
//        batchProduct.setProjectName(productInfo.getProjectName());
        System.out.println("是否为标准柜体：" + productInfo.getIsStandard());
        if (productInfo.getIsStandard() == 1) { //标准柜体

            batchProduct.setStandardProductCode(productInfo.getStandTypeCode());
            StandProduct standProduct = standProductRepository.findStandProductByStandTypeCodeAndDelete(productInfo.getStandTypeCode(), 0);
//            if (standProduct == null) throw new BeadminException("未找到该标准柜体");
//            //设置图纸 BOM 和BOP
//            if (standProduct.getStandBomFileCode() != null) {
//                //将BOM添加到这个表中 productBomOverview
//                batchProduct.setBomId(standProduct.getStandBomFileCode());
//                batchProduct.setIsBomUploaded(1);
//            }
//            if (standProduct.getStandDrawingFileCode() != null) {
//                //将图纸添加到这个表中 productDrawingOverview
//
//                batchProduct.setDrawingId(standProduct.getStandDrawingFileCode());
//                batchProduct.setIsDrawingUploaded(1);
//            }
            if (standProduct.getBopCode() != null) {

                batchProduct.setBopCode(standProduct.getBopCode());
                batchProduct.setIsBomUploaded(1);
                // 将每道工序添加到这个表中 productManufactOverview

            }
//            if (batchProduct.getBomId() != null && batchProduct.getDrawingId() != null && batchProduct.getBopCode() != null) {
//                batchProduct.setReviewState(1);
//            }
            //            batchProductxDto
        }
//        BatchProduct batchProduct = batchProductMapper.toEntity(batchProductDto);
        batchProductRepository.save(batchProduct);
    }


    //查询未提交审核
    public Page<Object> getBatchProductDesign0(HttpServletRequest request, PageEntity pageEntity) {

        UserEx userEx = userService.viewBaseInfo(request);
        String userId = userEx.getId();


//        Page<BatchProduct> page = batchProductService.getBatchProductEntityByPage(pageEntity);
        Page<BatchProduct> page = batchProductService.getBatchProductDesignByPage(pageEntity);

        Page<Object> map = page.map(new Function<BatchProduct, Object>() {

            @Override
            public BatchProductDesign apply(BatchProduct b) {
                //通过infoid获取当前项目团队的技术工程师以及技术经理的id；
                String infoId = b.getInfoId();
                Info info = infoRepository.findInfoByIdAndDelete(infoId, 0);
                String techManager = null;
                String tech = null;
                TeamInfo teamInfo = teamInfoRepository.findTeamInfoByTeamIdAndCategoryAndDelete(info.getTeamId(), "技术经理", 0);
                if (teamInfo != null) {
                    techManager = teamInfo.getUserId();
                }
                TeamInfo teamInfo2 = teamInfoRepository.findTeamInfoByTeamIdAndCategoryAndDelete(info.getTeamId(), "技术人员", 0);
                if (!(teamInfo2 == null)) {
                    tech = teamInfo2.getUserId();
                }
                BatchProductDesign batchProductDesign = new BatchProductDesign();
                batchProductDesign.setInfoId(infoId);

                if (!(userId.equals(tech) || userId.equals(techManager)||userId.equals("402881ed854de8d201854de911030000"))) {
                    return null;
                }
//                if (b.getBatchPlanId().equals("-1")) {
//                    return null;
//                }
                //System.out.println(b.getBatchPlanId());
                if (Objects.equals(b.getBatchPlanId(), "-1")) return null;
                BatchPlan batchPlan = batchPlanRepository.findBatchPlanById(b.getBatchPlanId());
                PlanStage designStage = batchPlanService.getStageByBatchPlanAndStageName(batchPlan, "柜体设计");
                PlanStage kickOffStage = batchPlanService.getStageByBatchPlanAndStageName(batchPlan, "项目开工");
//                PlanStage stage = batchPlanService.getStageByBatchPlanAndStageName(batchPlan,"柜体设计");

                if (batchPlan == null) throw new BeadminException("为找该批次柜体的批次计划");
                MasterPlan masterPlan = masterPlanRepository.findMasterPlanByIdAndDelete(batchPlan.getMasterPlanId(), 0);
                //不需要判空，==0则是未上传
                if (b.getReviewState().equals(0)) {
                    batchProductDesign.setReviewState(b.getReviewState());
                } else {
                    return null;
                }
                if (b.getId() != null) {
                    batchProductDesign.setBatchProductId(b.getId());
                }
                if(info.getProjectCode()!=null){
                    batchProductDesign.setProjectCode(info.getProjectCode());
                }
                if (b.getReviewEditor() != null) {
                    batchProductDesign.setReviewEditor(b.getReviewEditor());
                }
                if (batchPlan.getCurrentBatch() != null && batchPlan.getBatchCount()!=null) {
                    batchProductDesign.setBatchPlanCode(batchPlan.getCurrentBatch()+"/"+batchPlan.getBatchCount());
                }
                batchProductDesign.setState(b.getState());
                batchProductDesign.setPlanDesignWh(b.getPlanDesignWh());

                if (designStage.getStagePlanEndTime() != null) {
                    batchProductDesign.setPlanDesignEndDate(designStage.getStagePlanEndTime());
                }
                if (kickOffStage.getStageStartTime() != null) {
                    batchProductDesign.setActualKickoffStartDate(kickOffStage.getStageStartTime());
                }
                if (batchPlan.getProjectName() != null) {
                    batchProductDesign.setProjectName(batchPlan.getProjectName());
                }
                if (batchPlan.getBatchDeliveryDate() != null) {
                    batchProductDesign.setBatchDeliveryDate(batchPlan.getBatchDeliveryDate());
                }
                if (b.getProductType() != null) {
                    batchProductDesign.setProductType(b.getProductType());
                }

                if (b.getProductCode() != null) {
                    batchProductDesign.setProductCode(b.getProductCode());
                }
                if (b.getBopCode() != null) {
                    batchProductDesign.setBopCode(b.getBopCode());
                }
                if (designStage.getStagePlanStartTime() != null) {
                    batchProductDesign.setPlanDesignStartDate(designStage.getStagePlanStartTime());
                }
                if (batchPlan.getMasterPlanId() != null) {
                    String masterPlanId = batchPlan.getMasterPlanId();
                    MasterPlan masterPlanByIdAndDelete = masterPlanRepository.findMasterPlanByIdAndDelete(masterPlanId, 0);
                    batchProductDesign.setMasterPlanCode(masterPlanByIdAndDelete.getMasterPlanCode());
                }
                if (b.getIsStandard() != null) {
                    batchProductDesign.setIsStandard(b.getIsStandard());
                }
                if (batchPlan.getId() != null) {
                    batchProductDesign.setBatchPlanId(batchPlan.getId());
                }


                return batchProductDesign;
            }
        });
        return map;
    }

    //查询未提交审核-过滤项目名称
    public Page<Object> getBatchProductDesign01(String projectName, HttpServletRequest request, PageEntity pageEntity) {

        UserEx userEx = userService.viewBaseInfo(request);
        String userId = userEx.getId();


//        Page<BatchProduct> page = batchProductService.getBatchProductEntityByPage(pageEntity);
        Page<BatchProduct> page = batchProductService.getBatchProductDesignByPage(pageEntity);

        Page<Object> map = page.map(new Function<BatchProduct, Object>() {

            @Override
            public BatchProductDesign apply(BatchProduct b) {
                //通过infoid获取当前项目团队的技术工程师以及技术经理的id；
                String infoId = b.getInfoId();
                Info info = infoRepository.findInfoByIdAndDelete(infoId, 0);
                if(!info.getProjectName().equals(projectName)){
                    return null;
                }
                String techManager = null;
                String tech = null;
                TeamInfo teamInfo = teamInfoRepository.findTeamInfoByTeamIdAndCategoryAndDelete(info.getTeamId(), "技术经理", 0);
                if (teamInfo != null) {
                    techManager = teamInfo.getUserId();
                }
                TeamInfo teamInfo2 = teamInfoRepository.findTeamInfoByTeamIdAndCategoryAndDelete(info.getTeamId(), "技术人员", 0);
                if (!(teamInfo2 == null)) {
                    tech = teamInfo2.getUserId();
                }
                BatchProductDesign batchProductDesign = new BatchProductDesign();

                if (!(userId.equals(tech) || userId.equals(techManager)||userId.equals("402881ed854de8d201854de911030000"))) {
                    return null;
                }
//                if (b.getBatchPlanId().equals("-1")) {
//                    return null;
//                }
                //System.out.println(b.getBatchPlanId());
                if (Objects.equals(b.getBatchPlanId(), "-1")) return null;
                BatchPlan batchPlan = batchPlanRepository.findBatchPlanById(b.getBatchPlanId());
                PlanStage designStage = batchPlanService.getStageByBatchPlanAndStageName(batchPlan, "柜体设计");
                PlanStage kickOffStage = batchPlanService.getStageByBatchPlanAndStageName(batchPlan, "项目开工");
//                PlanStage stage = batchPlanService.getStageByBatchPlanAndStageName(batchPlan,"柜体设计");

                if (batchPlan == null) throw new BeadminException("为找该批次柜体的批次计划");
                MasterPlan masterPlan = masterPlanRepository.findMasterPlanByIdAndDelete(batchPlan.getMasterPlanId(), 0);
                //不需要判空，==0则是未上传
                if (b.getReviewState().equals(0)) {
                    batchProductDesign.setReviewState(b.getReviewState());
                } else {
                    return null;
                }
                if (b.getId() != null) {
                    batchProductDesign.setBatchProductId(b.getId());
                }
                if(info.getProjectCode()!=null){
                    batchProductDesign.setProjectCode(info.getProjectCode());
                }
                if (b.getReviewEditor() != null) {
                    batchProductDesign.setReviewEditor(b.getReviewEditor());
                }
                if (batchPlan.getCurrentBatch() != null && batchPlan.getBatchCount()!=null) {
                    batchProductDesign.setBatchPlanCode(batchPlan.getCurrentBatch()+"/"+batchPlan.getBatchCount());
                }
                batchProductDesign.setState(b.getState());
                batchProductDesign.setPlanDesignWh(b.getPlanDesignWh());

                if (designStage.getStagePlanEndTime() != null) {
                    batchProductDesign.setPlanDesignEndDate(designStage.getStagePlanEndTime());
                }
                if (kickOffStage.getStageStartTime() != null) {
                    batchProductDesign.setActualKickoffStartDate(kickOffStage.getStageStartTime());
                }
                if (batchPlan.getProjectName() != null) {
                    batchProductDesign.setProjectName(batchPlan.getProjectName());
                }
                if (batchPlan.getBatchDeliveryDate() != null) {
                    batchProductDesign.setBatchDeliveryDate(batchPlan.getBatchDeliveryDate());
                }
                if (b.getProductType() != null) {
                    batchProductDesign.setProductType(b.getProductType());
                }

                if (b.getProductCode() != null) {
                    batchProductDesign.setProductCode(b.getProductCode());
                }
                if (b.getBopCode() != null) {
                    batchProductDesign.setBopCode(b.getBopCode());
                }
                if (designStage.getStagePlanStartTime() != null) {
                    batchProductDesign.setPlanDesignStartDate(designStage.getStagePlanStartTime());
                }
                if (batchPlan.getMasterPlanId() != null) {
                    String masterPlanId = batchPlan.getMasterPlanId();
                    MasterPlan masterPlanByIdAndDelete = masterPlanRepository.findMasterPlanByIdAndDelete(masterPlanId, 0);
                    batchProductDesign.setMasterPlanCode(masterPlanByIdAndDelete.getMasterPlanCode());
                }
                if (b.getIsStandard() != null) {
                    batchProductDesign.setIsStandard(b.getIsStandard());
                }
                if (batchPlan.getId() != null) {
                    batchProductDesign.setBatchPlanId(batchPlan.getId());
                }
                return batchProductDesign;
            }
        });
        return map;
    }

    //查询未提交审核-过滤项目编码
    public Page<Object> getBatchProductDesign02(String projectCode, HttpServletRequest request, PageEntity pageEntity) {

        UserEx userEx = userService.viewBaseInfo(request);
        String userId = userEx.getId();


//        Page<BatchProduct> page = batchProductService.getBatchProductEntityByPage(pageEntity);
        Page<BatchProduct> page = batchProductService.getBatchProductDesignByPage(pageEntity);

        Page<Object> map = page.map(new Function<BatchProduct, Object>() {

            @Override
            public BatchProductDesign apply(BatchProduct b) {
                //通过infoid获取当前项目团队的技术工程师以及技术经理的id；
                String infoId = b.getInfoId();
                Info info = infoRepository.findInfoByIdAndDelete(infoId, 0);
                if(!info.getProjectCode().equals(projectCode)){
                    return null;
                }
                String techManager = null;
                String tech = null;
                TeamInfo teamInfo = teamInfoRepository.findTeamInfoByTeamIdAndCategoryAndDelete(info.getTeamId(), "技术经理", 0);
                if (teamInfo != null) {
                    techManager = teamInfo.getUserId();
                }
                TeamInfo teamInfo2 = teamInfoRepository.findTeamInfoByTeamIdAndCategoryAndDelete(info.getTeamId(), "技术人员", 0);
                if (!(teamInfo2 == null)) {
                    tech = teamInfo2.getUserId();
                }
                BatchProductDesign batchProductDesign = new BatchProductDesign();

                if (!(userId.equals(tech) || userId.equals(techManager)||userId.equals("402881ed854de8d201854de911030000"))) {
                    return null;
                }
//                if (b.getBatchPlanId().equals("-1")) {
//                    return null;
//                }
                //System.out.println(b.getBatchPlanId());
                if (Objects.equals(b.getBatchPlanId(), "-1")) return null;
                BatchPlan batchPlan = batchPlanRepository.findBatchPlanById(b.getBatchPlanId());
                PlanStage designStage = batchPlanService.getStageByBatchPlanAndStageName(batchPlan, "柜体设计");
                PlanStage kickOffStage = batchPlanService.getStageByBatchPlanAndStageName(batchPlan, "项目开工");
//                PlanStage stage = batchPlanService.getStageByBatchPlanAndStageName(batchPlan,"柜体设计");

                if (batchPlan == null) throw new BeadminException("为找该批次柜体的批次计划");
                MasterPlan masterPlan = masterPlanRepository.findMasterPlanByIdAndDelete(batchPlan.getMasterPlanId(), 0);
                //不需要判空，==0则是未上传
                if (b.getReviewState().equals(0)) {
                    batchProductDesign.setReviewState(b.getReviewState());
                } else {
                    return null;
                }
                if (b.getId() != null) {
                    batchProductDesign.setBatchProductId(b.getId());
                }
                if(info.getProjectCode()!=null){
                    batchProductDesign.setProjectCode(info.getProjectCode());
                }
                if (b.getReviewEditor() != null) {
                    batchProductDesign.setReviewEditor(b.getReviewEditor());
                }
                if (batchPlan.getCurrentBatch() != null && batchPlan.getBatchCount()!=null) {
                    batchProductDesign.setBatchPlanCode(batchPlan.getCurrentBatch()+"/"+batchPlan.getBatchCount());
                }
                batchProductDesign.setState(b.getState());
                batchProductDesign.setPlanDesignWh(b.getPlanDesignWh());

                if (designStage.getStagePlanEndTime() != null) {
                    batchProductDesign.setPlanDesignEndDate(designStage.getStagePlanEndTime());
                }
                if (kickOffStage.getStageStartTime() != null) {
                    batchProductDesign.setActualKickoffStartDate(kickOffStage.getStageStartTime());
                }
                if (batchPlan.getProjectName() != null) {
                    batchProductDesign.setProjectName(batchPlan.getProjectName());
                }
                if (batchPlan.getBatchDeliveryDate() != null) {
                    batchProductDesign.setBatchDeliveryDate(batchPlan.getBatchDeliveryDate());
                }
                if (b.getProductType() != null) {
                    batchProductDesign.setProductType(b.getProductType());
                }

                if (b.getProductCode() != null) {
                    batchProductDesign.setProductCode(b.getProductCode());
                }
                if (b.getBopCode() != null) {
                    batchProductDesign.setBopCode(b.getBopCode());
                }
                if (designStage.getStagePlanStartTime() != null) {
                    batchProductDesign.setPlanDesignStartDate(designStage.getStagePlanStartTime());
                }
                if (batchPlan.getMasterPlanId() != null) {
                    String masterPlanId = batchPlan.getMasterPlanId();
                    MasterPlan masterPlanByIdAndDelete = masterPlanRepository.findMasterPlanByIdAndDelete(masterPlanId, 0);
                    batchProductDesign.setMasterPlanCode(masterPlanByIdAndDelete.getMasterPlanCode());
                }
                if (b.getIsStandard() != null) {
                    batchProductDesign.setIsStandard(b.getIsStandard());
                }
                if (batchPlan.getId() != null) {
                    batchProductDesign.setBatchPlanId(batchPlan.getId());
                }
                return batchProductDesign;
            }
        });
        return map;
    }

    //查询待审核
    public Page<Object> getBatchProductDesign1(HttpServletRequest request, PageEntity pageEntity) {
        UserEx userEx = userService.viewBaseInfo(request);
        String userId = userEx.getId();

//        Page<BatchProduct> page = batchProductService.getBatchProductEntityByPage(pageEntity);
        Page<BatchProduct> page = batchProductService.getBatchProductDesignByPage(pageEntity);

        Page<Object> map = page.map(new Function<BatchProduct, Object>() {

            @Override
            public Object apply(BatchProduct b) {
                //通过infoid获取当前项目团队的技术工程师以及技术经理的id；
                String infoId = b.getInfoId();
                Info info = infoRepository.findInfoByIdAndDelete(infoId, 0);
                TeamInfo teamInfo = teamInfoRepository.findTeamInfoByTeamIdAndCategoryAndDelete(info.getTeamId(), "技术经理", 0);
                String techManager = null;
                if (teamInfo != null) {
                    techManager = teamInfo.getUserId();
                }

                if (!(userId.equals(techManager)||userId.equals("402881ed854de8d201854de911030000"))) {
                    return null;
                }
                BatchProductDesign batchProductDesign = new BatchProductDesign();
                //不需要判空，==1则是待审核
                if (b.getReviewState().equals(1)) {
                    batchProductDesign.setReviewState(b.getReviewState());
                } else {
                    return null;
                }
                //获取审核人员id

//                if (b.getBatchPlanId().equals("-1")) {
//                    return null;
//                }
                //System.out.println(b.getBatchPlanId());
                if (Objects.equals(b.getBatchPlanId(), "-1")) return null;
                BatchPlan batchPlan = batchPlanRepository.findBatchPlanById(b.getBatchPlanId());
                PlanStage designStage = batchPlanService.getStageByBatchPlanAndStageName(batchPlan, "柜体设计");
                PlanStage kickOffStage = batchPlanService.getStageByBatchPlanAndStageName(batchPlan, "项目开工");
//                PlanStage stage = batchPlanService.getStageByBatchPlanAndStageName(batchPlan,"柜体设计");

                if (batchPlan == null) throw new BeadminException("为找该批次柜体的批次计划");
                MasterPlan masterPlan = masterPlanRepository.findMasterPlanByIdAndDelete(batchPlan.getMasterPlanId(), 0);

                if (b.getId() != null) {
                    batchProductDesign.setBatchProductId(b.getId());
                }
                if(info.getProjectCode()!=null){
                    batchProductDesign.setProjectCode(info.getProjectCode());
                }
                if (b.getReviewEditor() != null) {
                    batchProductDesign.setReviewEditor(b.getReviewEditor());
                }
                if (batchPlan.getCurrentBatch() != null && batchPlan.getBatchCount()!=null) {
                    batchProductDesign.setBatchPlanCode(batchPlan.getCurrentBatch()+"/"+batchPlan.getBatchCount());
                }
                batchProductDesign.setState(b.getState());

                batchProductDesign.setPlanDesignWh(b.getPlanDesignWh());

                if (designStage.getStagePlanEndTime() != null) {
                    batchProductDesign.setPlanDesignEndDate(designStage.getStagePlanEndTime());
                }
                if (kickOffStage.getStageStartTime() != null) {
                    batchProductDesign.setActualKickoffStartDate(kickOffStage.getStageStartTime());
                }
                if (batchPlan.getProjectName() != null) {
                    batchProductDesign.setProjectName(batchPlan.getProjectName());
                }
                if (batchPlan.getBatchDeliveryDate() != null) {
                    batchProductDesign.setBatchDeliveryDate(batchPlan.getBatchDeliveryDate());
                }
                if (b.getProductType() != null) {
                    batchProductDesign.setProductType(b.getProductType());
                }

                if (b.getProductCode() != null) {
                    batchProductDesign.setProductCode(b.getProductCode());
                }
                if (b.getBopCode() != null) {
                    batchProductDesign.setBopCode(b.getBopCode());
                }
                if (designStage.getStagePlanStartTime() != null) {
                    batchProductDesign.setPlanDesignStartDate(designStage.getStagePlanStartTime());
                }
                if (batchPlan.getMasterPlanId() != null) {
                    String masterPlanId = batchPlan.getMasterPlanId();
                    MasterPlan masterPlanByIdAndDelete = masterPlanRepository.findMasterPlanByIdAndDelete(masterPlanId, 0);
                    batchProductDesign.setMasterPlanCode(masterPlanByIdAndDelete.getMasterPlanCode());
                }
                if (b.getIsStandard() != null) {
                    batchProductDesign.setIsStandard(b.getIsStandard());
                }
                if (batchPlan.getId() != null) {
                    batchProductDesign.setBatchPlanId(batchPlan.getId());
                }
                batchProductDesign.setInfoId(infoId);

                return batchProductDesign;
            }
        });
        return map;
    }

    //查询待审核-过滤项目名称
    public Page<Object> getBatchProductDesign11(String projectName,HttpServletRequest request, PageEntity pageEntity) {
        UserEx userEx = userService.viewBaseInfo(request);
        String userId = userEx.getId();

//        Page<BatchProduct> page = batchProductService.getBatchProductEntityByPage(pageEntity);
        Page<BatchProduct> page = batchProductService.getBatchProductDesignByPage(pageEntity);

        Page<Object> map = page.map(new Function<BatchProduct, Object>() {

            @Override
            public Object apply(BatchProduct b) {
                //通过infoid获取当前项目团队的技术工程师以及技术经理的id；
                String infoId = b.getInfoId();
                Info info = infoRepository.findInfoByIdAndDelete(infoId, 0);
                if(!info.getProjectName().equals(projectName)){
                    return null;
                }
                TeamInfo teamInfo = teamInfoRepository.findTeamInfoByTeamIdAndCategoryAndDelete(info.getTeamId(), "技术经理", 0);
                String techManager = null;
                if (teamInfo != null) {
                    techManager = teamInfo.getUserId();
                }

                if (!(userId.equals(techManager)||userId.equals("402881ed854de8d201854de911030000"))) {
                    return null;
                }
                BatchProductDesign batchProductDesign = new BatchProductDesign();
                //不需要判空，==1则是待审核
                if (b.getReviewState().equals(1)) {
                    batchProductDesign.setReviewState(b.getReviewState());
                } else {
                    return null;
                }
                //获取审核人员id

//                if (b.getBatchPlanId().equals("-1")) {
//                    return null;
//                }
                //System.out.println(b.getBatchPlanId());
                if (Objects.equals(b.getBatchPlanId(), "-1")) return null;
                BatchPlan batchPlan = batchPlanRepository.findBatchPlanById(b.getBatchPlanId());
                PlanStage designStage = batchPlanService.getStageByBatchPlanAndStageName(batchPlan, "柜体设计");
                PlanStage kickOffStage = batchPlanService.getStageByBatchPlanAndStageName(batchPlan, "项目开工");
//                PlanStage stage = batchPlanService.getStageByBatchPlanAndStageName(batchPlan,"柜体设计");

                if (batchPlan == null) throw new BeadminException("为找该批次柜体的批次计划");
                MasterPlan masterPlan = masterPlanRepository.findMasterPlanByIdAndDelete(batchPlan.getMasterPlanId(), 0);

                if (b.getId() != null) {
                    batchProductDesign.setBatchProductId(b.getId());
                }
                if(info.getProjectCode()!=null){
                    batchProductDesign.setProjectCode(info.getProjectCode());
                }
                if (b.getReviewEditor() != null) {
                    batchProductDesign.setReviewEditor(b.getReviewEditor());
                }
                if (batchPlan.getCurrentBatch() != null && batchPlan.getBatchCount()!=null) {
                    batchProductDesign.setBatchPlanCode(batchPlan.getCurrentBatch()+"/"+batchPlan.getBatchCount());
                }
                batchProductDesign.setState(b.getState());

                batchProductDesign.setPlanDesignWh(b.getPlanDesignWh());

                if (designStage.getStagePlanEndTime() != null) {
                    batchProductDesign.setPlanDesignEndDate(designStage.getStagePlanEndTime());
                }
                if (kickOffStage.getStageStartTime() != null) {
                    batchProductDesign.setActualKickoffStartDate(kickOffStage.getStageStartTime());
                }
                if (batchPlan.getProjectName() != null) {
                    batchProductDesign.setProjectName(batchPlan.getProjectName());
                }
                if (batchPlan.getBatchDeliveryDate() != null) {
                    batchProductDesign.setBatchDeliveryDate(batchPlan.getBatchDeliveryDate());
                }
                if (b.getProductType() != null) {
                    batchProductDesign.setProductType(b.getProductType());
                }

                if (b.getProductCode() != null) {
                    batchProductDesign.setProductCode(b.getProductCode());
                }
                if (b.getBopCode() != null) {
                    batchProductDesign.setBopCode(b.getBopCode());
                }
                if (designStage.getStagePlanStartTime() != null) {
                    batchProductDesign.setPlanDesignStartDate(designStage.getStagePlanStartTime());
                }
                if (batchPlan.getMasterPlanId() != null) {
                    String masterPlanId = batchPlan.getMasterPlanId();
                    MasterPlan masterPlanByIdAndDelete = masterPlanRepository.findMasterPlanByIdAndDelete(masterPlanId, 0);
                    batchProductDesign.setMasterPlanCode(masterPlanByIdAndDelete.getMasterPlanCode());
                }
                if (b.getIsStandard() != null) {
                    batchProductDesign.setIsStandard(b.getIsStandard());
                }
                if (batchPlan.getId() != null) {
                    batchProductDesign.setBatchPlanId(batchPlan.getId());
                }
                return batchProductDesign;
            }
        });
        return map;
    }

    //查询待审核-过滤项目编码
    public Page<Object> getBatchProductDesign12(String projectCode,HttpServletRequest request, PageEntity pageEntity) {
        UserEx userEx = userService.viewBaseInfo(request);
        String userId = userEx.getId();

//        Page<BatchProduct> page = batchProductService.getBatchProductEntityByPage(pageEntity);
        Page<BatchProduct> page = batchProductService.getBatchProductDesignByPage(pageEntity);

        Page<Object> map = page.map(new Function<BatchProduct, Object>() {

            @Override
            public Object apply(BatchProduct b) {
                //通过infoid获取当前项目团队的技术工程师以及技术经理的id；
                String infoId = b.getInfoId();
                Info info = infoRepository.findInfoByIdAndDelete(infoId, 0);
                if(!info.getProjectCode().equals(projectCode)){
                    return null;
                }
                TeamInfo teamInfo = teamInfoRepository.findTeamInfoByTeamIdAndCategoryAndDelete(info.getTeamId(), "技术经理", 0);
                String techManager = null;
                if (teamInfo != null) {
                    techManager = teamInfo.getUserId();
                }

                if (!(userId.equals(techManager)||userId.equals("402881ed854de8d201854de911030000"))) {
                    return null;
                }
                BatchProductDesign batchProductDesign = new BatchProductDesign();
                //不需要判空，==1则是待审核
                if (b.getReviewState().equals(1)) {
                    batchProductDesign.setReviewState(b.getReviewState());
                } else {
                    return null;
                }
                //获取审核人员id

//                if (b.getBatchPlanId().equals("-1")) {
//                    return null;
//                }
                //System.out.println(b.getBatchPlanId());
                if (Objects.equals(b.getBatchPlanId(), "-1")) return null;
                BatchPlan batchPlan = batchPlanRepository.findBatchPlanById(b.getBatchPlanId());
                PlanStage designStage = batchPlanService.getStageByBatchPlanAndStageName(batchPlan, "柜体设计");
                PlanStage kickOffStage = batchPlanService.getStageByBatchPlanAndStageName(batchPlan, "项目开工");
//                PlanStage stage = batchPlanService.getStageByBatchPlanAndStageName(batchPlan,"柜体设计");

                if (batchPlan == null) throw new BeadminException("为找该批次柜体的批次计划");
                MasterPlan masterPlan = masterPlanRepository.findMasterPlanByIdAndDelete(batchPlan.getMasterPlanId(), 0);

                if (b.getId() != null) {
                    batchProductDesign.setBatchProductId(b.getId());
                }
                if(info.getProjectCode()!=null){
                    batchProductDesign.setProjectCode(info.getProjectCode());
                }
                if (b.getReviewEditor() != null) {
                    batchProductDesign.setReviewEditor(b.getReviewEditor());
                }
                if (batchPlan.getCurrentBatch() != null && batchPlan.getBatchCount()!=null) {
                    batchProductDesign.setBatchPlanCode(batchPlan.getCurrentBatch()+"/"+batchPlan.getBatchCount());
                }
                batchProductDesign.setState(b.getState());

                batchProductDesign.setPlanDesignWh(b.getPlanDesignWh());

                if (designStage.getStagePlanEndTime() != null) {
                    batchProductDesign.setPlanDesignEndDate(designStage.getStagePlanEndTime());
                }
                if (kickOffStage.getStageStartTime() != null) {
                    batchProductDesign.setActualKickoffStartDate(kickOffStage.getStageStartTime());
                }
                if (batchPlan.getProjectName() != null) {
                    batchProductDesign.setProjectName(batchPlan.getProjectName());
                }
                if (batchPlan.getBatchDeliveryDate() != null) {
                    batchProductDesign.setBatchDeliveryDate(batchPlan.getBatchDeliveryDate());
                }
                if (b.getProductType() != null) {
                    batchProductDesign.setProductType(b.getProductType());
                }

                if (b.getProductCode() != null) {
                    batchProductDesign.setProductCode(b.getProductCode());
                }
                if (b.getBopCode() != null) {
                    batchProductDesign.setBopCode(b.getBopCode());
                }
                if (designStage.getStagePlanStartTime() != null) {
                    batchProductDesign.setPlanDesignStartDate(designStage.getStagePlanStartTime());
                }
                if (batchPlan.getMasterPlanId() != null) {
                    String masterPlanId = batchPlan.getMasterPlanId();
                    MasterPlan masterPlanByIdAndDelete = masterPlanRepository.findMasterPlanByIdAndDelete(masterPlanId, 0);
                    batchProductDesign.setMasterPlanCode(masterPlanByIdAndDelete.getMasterPlanCode());
                }
                if (b.getIsStandard() != null) {
                    batchProductDesign.setIsStandard(b.getIsStandard());
                }
                if (batchPlan.getId() != null) {
                    batchProductDesign.setBatchPlanId(batchPlan.getId());
                }
                return batchProductDesign;
            }
        });
        return map;
    }

    //查询已审核
    public Page<Object> getBatchProductDesign2(HttpServletRequest request, PageEntity pageEntity) {

        UserEx userEx = userService.viewBaseInfo(request);
        String userId = userEx.getId();


//        Page<BatchProduct> page = batchProductService.getBatchProductEntityByPage(pageEntity);
        Page<BatchProduct> page = batchProductService.getBatchProductDesignByPage(pageEntity);

        Page<Object> map = page.map(new Function<BatchProduct, Object>() {

            @Override
            public Object apply(BatchProduct b) {
                //通过infoid获取当前项目团队的技术工程师以及技术经理的id；
                String infoId = b.getInfoId();
                Info info = infoRepository.findInfoByIdAndDelete(infoId, 0);
                String techManager = null;
                String tech = null;
                TeamInfo teamInfo = teamInfoRepository.findTeamInfoByTeamIdAndCategoryAndDelete(info.getTeamId(), "技术经理", 0);
                if (teamInfo != null) {
                    techManager = teamInfo.getUserId();
                }
                TeamInfo teamInfo2 = teamInfoRepository.findTeamInfoByTeamIdAndCategoryAndDelete(info.getTeamId(), "技术人员", 0);
                if (!(teamInfo2 == null)) {
                    tech = teamInfo2.getUserId();
                }
                BatchProductDesign batchProductDesign = new BatchProductDesign();

                if (!(userId.equals(tech) || userId.equals(techManager)||userId.equals("402881ed854de8d201854de911030000"))) {
                    return null;
                }
//                if (b.getBatchPlanId().equals("-1")) {
//                    return null;
//                }
                //System.out.println(b.getBatchPlanId());
                if (Objects.equals(b.getBatchPlanId(), "-1")) return null;
                BatchPlan batchPlan = batchPlanRepository.findBatchPlanById(b.getBatchPlanId());
                PlanStage designStage = batchPlanService.getStageByBatchPlanAndStageName(batchPlan, "柜体设计");
                PlanStage kickOffStage = batchPlanService.getStageByBatchPlanAndStageName(batchPlan, "项目开工");
//                PlanStage stage = batchPlanService.getStageByBatchPlanAndStageName(batchPlan,"柜体设计");

                if (batchPlan == null) throw new BeadminException("为找该批次柜体的批次计划");
                MasterPlan masterPlan = masterPlanRepository.findMasterPlanByIdAndDelete(batchPlan.getMasterPlanId(), 0);
                //不需要判空，==2则是已审核
                if (b.getReviewState().equals(2)) {
                    batchProductDesign.setReviewState(b.getReviewState());
                } else {
                    return null;
                }
                if (b.getId() != null) {
                    batchProductDesign.setBatchProductId(b.getId());
                }
                if(info.getProjectCode()!=null){
                    batchProductDesign.setProjectCode(info.getProjectCode());
                }
                if (b.getReviewEditor() != null) {
                    batchProductDesign.setReviewEditor(b.getReviewEditor());
                }
                if (batchPlan.getCurrentBatch() != null && batchPlan.getBatchCount()!=null) {
                    batchProductDesign.setBatchPlanCode(batchPlan.getCurrentBatch()+"/"+batchPlan.getBatchCount());
                }
                batchProductDesign.setState(b.getState());

                batchProductDesign.setPlanDesignWh(b.getPlanDesignWh());

                if (designStage.getStagePlanEndTime() != null) {
                    batchProductDesign.setPlanDesignEndDate(designStage.getStagePlanEndTime());
                }
                if (kickOffStage.getStageStartTime() != null) {
                    batchProductDesign.setActualKickoffStartDate(kickOffStage.getStageStartTime());
                }
                if (batchPlan.getProjectName() != null) {
                    batchProductDesign.setProjectName(batchPlan.getProjectName());
                }
                if (batchPlan.getBatchDeliveryDate() != null) {
                    batchProductDesign.setBatchDeliveryDate(batchPlan.getBatchDeliveryDate());
                }
                if (b.getProductType() != null) {
                    batchProductDesign.setProductType(b.getProductType());
                }

                if (b.getProductCode() != null) {
                    batchProductDesign.setProductCode(b.getProductCode());
                }
                if (b.getBopCode() != null) {
                    batchProductDesign.setBopCode(b.getBopCode());
                }
                if (designStage.getStagePlanStartTime() != null) {
                    batchProductDesign.setPlanDesignStartDate(designStage.getStagePlanStartTime());
                }
                if (batchPlan.getMasterPlanId() != null) {
                    String masterPlanId = batchPlan.getMasterPlanId();
                    MasterPlan masterPlanByIdAndDelete = masterPlanRepository.findMasterPlanByIdAndDelete(masterPlanId, 0);
                    batchProductDesign.setMasterPlanCode(masterPlanByIdAndDelete.getMasterPlanCode());
                }
                if (b.getIsStandard() != null) {
                    batchProductDesign.setIsStandard(b.getIsStandard());
                }
                if (batchPlan.getId() != null) {
                    batchProductDesign.setBatchPlanId(batchPlan.getId());
                }
                batchProductDesign.setInfoId(infoId);

                return batchProductDesign;
            }
        });
        return map;
    }

    //查询已审核-过滤项目名称
    public Page<Object> getBatchProductDesign21(String projectName,HttpServletRequest request, PageEntity pageEntity) {

        UserEx userEx = userService.viewBaseInfo(request);
        String userId = userEx.getId();


//        Page<BatchProduct> page = batchProductService.getBatchProductEntityByPage(pageEntity);
        Page<BatchProduct> page = batchProductService.getBatchProductDesignByPage(pageEntity);

        Page<Object> map = page.map(new Function<BatchProduct, Object>() {

            @Override
            public Object apply(BatchProduct b) {
                //通过infoid获取当前项目团队的技术工程师以及技术经理的id；
                String infoId = b.getInfoId();
                Info info = infoRepository.findInfoByIdAndDelete(infoId, 0);
                if(!info.getProjectName().equals(projectName)){
                    return null;
                }
                String techManager = null;
                String tech = null;
                TeamInfo teamInfo = teamInfoRepository.findTeamInfoByTeamIdAndCategoryAndDelete(info.getTeamId(), "技术经理", 0);
                if (teamInfo != null) {
                    techManager = teamInfo.getUserId();
                }
                TeamInfo teamInfo2 = teamInfoRepository.findTeamInfoByTeamIdAndCategoryAndDelete(info.getTeamId(), "技术人员", 0);
                if (!(teamInfo2 == null)) {
                    tech = teamInfo2.getUserId();
                }
                BatchProductDesign batchProductDesign = new BatchProductDesign();

                if (!(userId.equals(tech) || userId.equals(techManager)||userId.equals("402881ed854de8d201854de911030000"))) {
                    return null;
                }
//                if (b.getBatchPlanId().equals("-1")) {
//                    return null;
//                }
                //System.out.println(b.getBatchPlanId());
                if (Objects.equals(b.getBatchPlanId(), "-1")) return null;
                BatchPlan batchPlan = batchPlanRepository.findBatchPlanById(b.getBatchPlanId());
                PlanStage designStage = batchPlanService.getStageByBatchPlanAndStageName(batchPlan, "柜体设计");
                PlanStage kickOffStage = batchPlanService.getStageByBatchPlanAndStageName(batchPlan, "项目开工");
//                PlanStage stage = batchPlanService.getStageByBatchPlanAndStageName(batchPlan,"柜体设计");

                if (batchPlan == null) throw new BeadminException("为找该批次柜体的批次计划");
                MasterPlan masterPlan = masterPlanRepository.findMasterPlanByIdAndDelete(batchPlan.getMasterPlanId(), 0);
                //不需要判空，==2则是已审核
                if (b.getReviewState().equals(2)) {
                    batchProductDesign.setReviewState(b.getReviewState());
                } else {
                    return null;
                }
                if (b.getId() != null) {
                    batchProductDesign.setBatchProductId(b.getId());
                }
                if(info.getProjectCode()!=null){
                    batchProductDesign.setProjectCode(info.getProjectCode());
                }
                if (b.getReviewEditor() != null) {
                    batchProductDesign.setReviewEditor(b.getReviewEditor());
                }
                if (batchPlan.getCurrentBatch() != null && batchPlan.getBatchCount()!=null) {
                    batchProductDesign.setBatchPlanCode(batchPlan.getCurrentBatch()+"/"+batchPlan.getBatchCount());
                }
                batchProductDesign.setState(b.getState());

                batchProductDesign.setPlanDesignWh(b.getPlanDesignWh());

                if (designStage.getStagePlanEndTime() != null) {
                    batchProductDesign.setPlanDesignEndDate(designStage.getStagePlanEndTime());
                }
                if (kickOffStage.getStageStartTime() != null) {
                    batchProductDesign.setActualKickoffStartDate(kickOffStage.getStageStartTime());
                }
                if (batchPlan.getProjectName() != null) {
                    batchProductDesign.setProjectName(batchPlan.getProjectName());
                }
                if (batchPlan.getBatchDeliveryDate() != null) {
                    batchProductDesign.setBatchDeliveryDate(batchPlan.getBatchDeliveryDate());
                }
                if (b.getProductType() != null) {
                    batchProductDesign.setProductType(b.getProductType());
                }

                if (b.getProductCode() != null) {
                    batchProductDesign.setProductCode(b.getProductCode());
                }
                if (b.getBopCode() != null) {
                    batchProductDesign.setBopCode(b.getBopCode());
                }
                if (designStage.getStagePlanStartTime() != null) {
                    batchProductDesign.setPlanDesignStartDate(designStage.getStagePlanStartTime());
                }
                if (batchPlan.getMasterPlanId() != null) {
                    String masterPlanId = batchPlan.getMasterPlanId();
                    MasterPlan masterPlanByIdAndDelete = masterPlanRepository.findMasterPlanByIdAndDelete(masterPlanId, 0);
                    batchProductDesign.setMasterPlanCode(masterPlanByIdAndDelete.getMasterPlanCode());
                }
                if (b.getIsStandard() != null) {
                    batchProductDesign.setIsStandard(b.getIsStandard());
                }
                if (batchPlan.getId() != null) {
                    batchProductDesign.setBatchPlanId(batchPlan.getId());
                }
                return batchProductDesign;
            }
        });
        return map;
    }

    //查询已审核-过滤项目编码
    public Page<Object> getBatchProductDesign22(String projectCode,HttpServletRequest request, PageEntity pageEntity) {

        UserEx userEx = userService.viewBaseInfo(request);
        String userId = userEx.getId();


//        Page<BatchProduct> page = batchProductService.getBatchProductEntityByPage(pageEntity);
        Page<BatchProduct> page = batchProductService.getBatchProductDesignByPage(pageEntity);

        Page<Object> map = page.map(new Function<BatchProduct, Object>() {

            @Override
            public Object apply(BatchProduct b) {
                //通过infoid获取当前项目团队的技术工程师以及技术经理的id；
                String infoId = b.getInfoId();
                Info info = infoRepository.findInfoByIdAndDelete(infoId, 0);
                if(!info.getProjectCode().equals(projectCode)){
                    return null;
                }
                String techManager = null;
                String tech = null;
                TeamInfo teamInfo = teamInfoRepository.findTeamInfoByTeamIdAndCategoryAndDelete(info.getTeamId(), "技术经理", 0);
                if (teamInfo != null) {
                    techManager = teamInfo.getUserId();
                }
                TeamInfo teamInfo2 = teamInfoRepository.findTeamInfoByTeamIdAndCategoryAndDelete(info.getTeamId(), "技术人员", 0);
                if (!(teamInfo2 == null)) {
                    tech = teamInfo2.getUserId();
                }
                BatchProductDesign batchProductDesign = new BatchProductDesign();

                if (!(userId.equals(tech) || userId.equals(techManager)||userId.equals("402881ed854de8d201854de911030000"))) {
                    return null;
                }
//                if (b.getBatchPlanId().equals("-1")) {
//                    return null;
//                }
                //System.out.println(b.getBatchPlanId());
                if (Objects.equals(b.getBatchPlanId(), "-1")) return null;
                BatchPlan batchPlan = batchPlanRepository.findBatchPlanById(b.getBatchPlanId());
                PlanStage designStage = batchPlanService.getStageByBatchPlanAndStageName(batchPlan, "柜体设计");
                PlanStage kickOffStage = batchPlanService.getStageByBatchPlanAndStageName(batchPlan, "项目开工");
//                PlanStage stage = batchPlanService.getStageByBatchPlanAndStageName(batchPlan,"柜体设计");

                if (batchPlan == null) throw new BeadminException("为找该批次柜体的批次计划");
                MasterPlan masterPlan = masterPlanRepository.findMasterPlanByIdAndDelete(batchPlan.getMasterPlanId(), 0);
                //不需要判空，==2则是已审核
                if (b.getReviewState().equals(2)) {
                    batchProductDesign.setReviewState(b.getReviewState());
                } else {
                    return null;
                }
                if (b.getId() != null) {
                    batchProductDesign.setBatchProductId(b.getId());
                }
                if(info.getProjectCode()!=null){
                    batchProductDesign.setProjectCode(info.getProjectCode());
                }
                if (b.getReviewEditor() != null) {
                    batchProductDesign.setReviewEditor(b.getReviewEditor());
                }
                if (batchPlan.getCurrentBatch() != null && batchPlan.getBatchCount()!=null) {
                    batchProductDesign.setBatchPlanCode(batchPlan.getCurrentBatch()+"/"+batchPlan.getBatchCount());
                }
                batchProductDesign.setState(b.getState());

                batchProductDesign.setPlanDesignWh(b.getPlanDesignWh());

                if (designStage.getStagePlanEndTime() != null) {
                    batchProductDesign.setPlanDesignEndDate(designStage.getStagePlanEndTime());
                }
                if (kickOffStage.getStageStartTime() != null) {
                    batchProductDesign.setActualKickoffStartDate(kickOffStage.getStageStartTime());
                }
                if (batchPlan.getProjectName() != null) {
                    batchProductDesign.setProjectName(batchPlan.getProjectName());
                }
                if (batchPlan.getBatchDeliveryDate() != null) {
                    batchProductDesign.setBatchDeliveryDate(batchPlan.getBatchDeliveryDate());
                }
                if (b.getProductType() != null) {
                    batchProductDesign.setProductType(b.getProductType());
                }

                if (b.getProductCode() != null) {
                    batchProductDesign.setProductCode(b.getProductCode());
                }
                if (b.getBopCode() != null) {
                    batchProductDesign.setBopCode(b.getBopCode());
                }
                if (designStage.getStagePlanStartTime() != null) {
                    batchProductDesign.setPlanDesignStartDate(designStage.getStagePlanStartTime());
                }
                if (batchPlan.getMasterPlanId() != null) {
                    String masterPlanId = batchPlan.getMasterPlanId();
                    MasterPlan masterPlanByIdAndDelete = masterPlanRepository.findMasterPlanByIdAndDelete(masterPlanId, 0);
                    batchProductDesign.setMasterPlanCode(masterPlanByIdAndDelete.getMasterPlanCode());
                }
                if (b.getIsStandard() != null) {
                    batchProductDesign.setIsStandard(b.getIsStandard());
                }
                if (batchPlan.getId() != null) {
                    batchProductDesign.setBatchPlanId(batchPlan.getId());
                }
                return batchProductDesign;
            }
        });
        return map;
    }


    //查询已下发
    public Page<Object> getBatchProductDesign3(HttpServletRequest request, PageEntity pageEntity) {

        UserEx userEx = userService.viewBaseInfo(request);
        String userId = userEx.getId();


//        Page<BatchProduct> page = batchProductService.getBatchProductEntityByPage(pageEntity);
        Page<BatchProduct> page = batchProductService.getBatchProductDesignReleasedByPage(pageEntity);

        Page<Object> map = page.map(new Function<BatchProduct, Object>() {

            @Override
            public Object apply(BatchProduct b) {
                //通过infoid获取当前项目团队的技术工程师以及技术经理的id；
                String infoId = b.getInfoId();
                Info info = infoRepository.findInfoByIdAndDelete(infoId, 0);
                String techManager = null;
                String tech = null;
                TeamInfo teamInfo = teamInfoRepository.findTeamInfoByTeamIdAndCategoryAndDelete(info.getTeamId(), "技术经理", 0);
                if (teamInfo != null) {
                    techManager = teamInfo.getUserId();
                }
                TeamInfo teamInfo2 = teamInfoRepository.findTeamInfoByTeamIdAndCategoryAndDelete(info.getTeamId(), "技术人员", 0);
                if (!(teamInfo2 == null)) {
                    tech = teamInfo2.getUserId();
                }
                BatchProductDesign batchProductDesign = new BatchProductDesign();

                if (!(userId.equals(tech) || userId.equals(techManager)||userId.equals("402881ed854de8d201854de911030000"))) {
                    return null;
                }
//                if (b.getBatchPlanId().equals("-1")) {
//                    return null;
//                }
                //System.out.println(b.getBatchPlanId());
                if (Objects.equals(b.getBatchPlanId(), "-1")) return null;
                BatchPlan batchPlan = batchPlanRepository.findBatchPlanById(b.getBatchPlanId());
                PlanStage designStage = batchPlanService.getStageByBatchPlanAndStageName(batchPlan, "柜体设计");
                PlanStage kickOffStage = batchPlanService.getStageByBatchPlanAndStageName(batchPlan, "项目开工");
//                PlanStage stage = batchPlanService.getStageByBatchPlanAndStageName(batchPlan,"柜体设计");

                if (batchPlan == null) throw new BeadminException("为找该批次柜体的批次计划");
                MasterPlan masterPlan = masterPlanRepository.findMasterPlanByIdAndDelete(batchPlan.getMasterPlanId(), 0);
                //不需要判空，==2则是已审核
                if (b.getReviewState().equals(2)) {
                    batchProductDesign.setReviewState(b.getReviewState());
                } else {
                    return null;
                }
                if (b.getId() != null) {
                    batchProductDesign.setBatchProductId(b.getId());
                }
                if(info.getProjectCode()!=null){
                    batchProductDesign.setProjectCode(info.getProjectCode());
                }
                if (b.getReviewEditor() != null) {
                    batchProductDesign.setReviewEditor(b.getReviewEditor());
                }
                if (batchPlan.getCurrentBatch() != null && batchPlan.getBatchCount()!=null) {
                    batchProductDesign.setBatchPlanCode(batchPlan.getCurrentBatch()+"/"+batchPlan.getBatchCount());
                }
                batchProductDesign.setState(b.getState());

                batchProductDesign.setPlanDesignWh(b.getPlanDesignWh());

                if (designStage.getStagePlanEndTime() != null) {
                    batchProductDesign.setPlanDesignEndDate(designStage.getStagePlanEndTime());
                }
                if (kickOffStage.getStageStartTime() != null) {
                    batchProductDesign.setActualKickoffStartDate(kickOffStage.getStageStartTime());
                }
                if (batchPlan.getProjectName() != null) {
                    batchProductDesign.setProjectName(batchPlan.getProjectName());
                }
                if (batchPlan.getBatchDeliveryDate() != null) {
                    batchProductDesign.setBatchDeliveryDate(batchPlan.getBatchDeliveryDate());
                }
                if (b.getProductType() != null) {
                    batchProductDesign.setProductType(b.getProductType());
                }

                if (b.getProductCode() != null) {
                    batchProductDesign.setProductCode(b.getProductCode());
                }
                if (b.getBopCode() != null) {
                    batchProductDesign.setBopCode(b.getBopCode());
                }
                if (designStage.getStagePlanStartTime() != null) {
                    batchProductDesign.setPlanDesignStartDate(designStage.getStagePlanStartTime());
                }
                if (batchPlan.getMasterPlanId() != null) {
                    String masterPlanId = batchPlan.getMasterPlanId();
                    MasterPlan masterPlanByIdAndDelete = masterPlanRepository.findMasterPlanByIdAndDelete(masterPlanId, 0);
                    batchProductDesign.setMasterPlanCode(masterPlanByIdAndDelete.getMasterPlanCode());
                }
                if (b.getIsStandard() != null) {
                    batchProductDesign.setIsStandard(b.getIsStandard());
                }
                if (batchPlan.getId() != null) {
                    batchProductDesign.setBatchPlanId(batchPlan.getId());
                }
                batchProductDesign.setInfoId(infoId);

                return batchProductDesign;
            }
        });
        return map;
    }

    //查询已下发
    public Page<Object> getBatchProductDesign31(String projectName,HttpServletRequest request, PageEntity pageEntity) {

        UserEx userEx = userService.viewBaseInfo(request);
        String userId = userEx.getId();


//        Page<BatchProduct> page = batchProductService.getBatchProductEntityByPage(pageEntity);
        Page<BatchProduct> page = batchProductService.getBatchProductDesignReleasedByPage(pageEntity);

        Page<Object> map = page.map(new Function<BatchProduct, Object>() {

            @Override
            public Object apply(BatchProduct b) {
                //通过infoid获取当前项目团队的技术工程师以及技术经理的id；
                String infoId = b.getInfoId();
                Info info = infoRepository.findInfoByIdAndDelete(infoId, 0);
                if(!info.getProjectName().equals(projectName)){
                    return null;
                }
                String techManager = null;
                String tech = null;
                TeamInfo teamInfo = teamInfoRepository.findTeamInfoByTeamIdAndCategoryAndDelete(info.getTeamId(), "技术经理", 0);
                if (teamInfo != null) {
                    techManager = teamInfo.getUserId();
                }
                TeamInfo teamInfo2 = teamInfoRepository.findTeamInfoByTeamIdAndCategoryAndDelete(info.getTeamId(), "技术人员", 0);
                if (!(teamInfo2 == null)) {
                    tech = teamInfo2.getUserId();
                }
                BatchProductDesign batchProductDesign = new BatchProductDesign();

                if (!(userId.equals(tech) || userId.equals(techManager)||userId.equals("402881ed854de8d201854de911030000"))) {
                    return null;
                }
//                if (b.getBatchPlanId().equals("-1")) {
//                    return null;
//                }
                //System.out.println(b.getBatchPlanId());
                if (Objects.equals(b.getBatchPlanId(), "-1")) return null;
                BatchPlan batchPlan = batchPlanRepository.findBatchPlanById(b.getBatchPlanId());
                PlanStage designStage = batchPlanService.getStageByBatchPlanAndStageName(batchPlan, "柜体设计");
                PlanStage kickOffStage = batchPlanService.getStageByBatchPlanAndStageName(batchPlan, "项目开工");
//                PlanStage stage = batchPlanService.getStageByBatchPlanAndStageName(batchPlan,"柜体设计");

                if (batchPlan == null) throw new BeadminException("为找该批次柜体的批次计划");
                MasterPlan masterPlan = masterPlanRepository.findMasterPlanByIdAndDelete(batchPlan.getMasterPlanId(), 0);
                //不需要判空，==2则是已审核
                if (b.getReviewState().equals(2)) {
                    batchProductDesign.setReviewState(b.getReviewState());
                } else {
                    return null;
                }
                if (b.getId() != null) {
                    batchProductDesign.setBatchProductId(b.getId());
                }
                if(info.getProjectCode()!=null){
                    batchProductDesign.setProjectCode(info.getProjectCode());
                }
                if (b.getReviewEditor() != null) {
                    batchProductDesign.setReviewEditor(b.getReviewEditor());
                }
                if (batchPlan.getCurrentBatch() != null && batchPlan.getBatchCount()!=null) {
                    batchProductDesign.setBatchPlanCode(batchPlan.getCurrentBatch()+"/"+batchPlan.getBatchCount());
                }
                batchProductDesign.setState(b.getState());

                batchProductDesign.setPlanDesignWh(b.getPlanDesignWh());

                if (designStage.getStagePlanEndTime() != null) {
                    batchProductDesign.setPlanDesignEndDate(designStage.getStagePlanEndTime());
                }
                if (kickOffStage.getStageStartTime() != null) {
                    batchProductDesign.setActualKickoffStartDate(kickOffStage.getStageStartTime());
                }
                if (batchPlan.getProjectName() != null) {
                    batchProductDesign.setProjectName(batchPlan.getProjectName());
                }
                if (batchPlan.getBatchDeliveryDate() != null) {
                    batchProductDesign.setBatchDeliveryDate(batchPlan.getBatchDeliveryDate());
                }
                if (b.getProductType() != null) {
                    batchProductDesign.setProductType(b.getProductType());
                }

                if (b.getProductCode() != null) {
                    batchProductDesign.setProductCode(b.getProductCode());
                }
                if (b.getBopCode() != null) {
                    batchProductDesign.setBopCode(b.getBopCode());
                }
                if (designStage.getStagePlanStartTime() != null) {
                    batchProductDesign.setPlanDesignStartDate(designStage.getStagePlanStartTime());
                }
                if (batchPlan.getMasterPlanId() != null) {
                    String masterPlanId = batchPlan.getMasterPlanId();
                    MasterPlan masterPlanByIdAndDelete = masterPlanRepository.findMasterPlanByIdAndDelete(masterPlanId, 0);
                    batchProductDesign.setMasterPlanCode(masterPlanByIdAndDelete.getMasterPlanCode());
                }
                if (b.getIsStandard() != null) {
                    batchProductDesign.setIsStandard(b.getIsStandard());
                }
                if (batchPlan.getId() != null) {
                    batchProductDesign.setBatchPlanId(batchPlan.getId());
                }
                return batchProductDesign;
            }
        });
        return map;
    }

    //查询已下发-过滤项目编码
    public Page<Object> getBatchProductDesign32(String projectCode,HttpServletRequest request, PageEntity pageEntity) {

        UserEx userEx = userService.viewBaseInfo(request);
        String userId = userEx.getId();


//        Page<BatchProduct> page = batchProductService.getBatchProductEntityByPage(pageEntity);
        Page<BatchProduct> page = batchProductService.getBatchProductDesignReleasedByPage(pageEntity);

        Page<Object> map = page.map(new Function<BatchProduct, Object>() {

            @Override
            public Object apply(BatchProduct b) {
                //通过infoid获取当前项目团队的技术工程师以及技术经理的id；
                String infoId = b.getInfoId();
                Info info = infoRepository.findInfoByIdAndDelete(infoId, 0);
                if(!info.getProjectCode().equals(projectCode)){
                    return null;
                }
                String techManager = null;
                String tech = null;
                TeamInfo teamInfo = teamInfoRepository.findTeamInfoByTeamIdAndCategoryAndDelete(info.getTeamId(), "技术经理", 0);
                if (teamInfo != null) {
                    techManager = teamInfo.getUserId();
                }
                TeamInfo teamInfo2 = teamInfoRepository.findTeamInfoByTeamIdAndCategoryAndDelete(info.getTeamId(), "技术人员", 0);
                if (!(teamInfo2 == null)) {
                    tech = teamInfo2.getUserId();
                }
                BatchProductDesign batchProductDesign = new BatchProductDesign();

                if (!(userId.equals(tech) || userId.equals(techManager)||userId.equals("402881ed854de8d201854de911030000"))) {
                    return null;
                }
//                if (b.getBatchPlanId().equals("-1")) {
//                    return null;
//                }
                //System.out.println(b.getBatchPlanId());
                if (Objects.equals(b.getBatchPlanId(), "-1")) return null;
                BatchPlan batchPlan = batchPlanRepository.findBatchPlanById(b.getBatchPlanId());
                PlanStage designStage = batchPlanService.getStageByBatchPlanAndStageName(batchPlan, "柜体设计");
                PlanStage kickOffStage = batchPlanService.getStageByBatchPlanAndStageName(batchPlan, "项目开工");
//                PlanStage stage = batchPlanService.getStageByBatchPlanAndStageName(batchPlan,"柜体设计");

                if (batchPlan == null) throw new BeadminException("为找该批次柜体的批次计划");
                MasterPlan masterPlan = masterPlanRepository.findMasterPlanByIdAndDelete(batchPlan.getMasterPlanId(), 0);
                //不需要判空，==2则是已审核
                if (b.getReviewState().equals(2)) {
                    batchProductDesign.setReviewState(b.getReviewState());
                } else {
                    return null;
                }
                if (b.getId() != null) {
                    batchProductDesign.setBatchProductId(b.getId());
                }
                if(info.getProjectCode()!=null){
                    batchProductDesign.setProjectCode(info.getProjectCode());
                }
                if (b.getReviewEditor() != null) {
                    batchProductDesign.setReviewEditor(b.getReviewEditor());
                }
                if (batchPlan.getCurrentBatch() != null && batchPlan.getBatchCount()!=null) {
                    batchProductDesign.setBatchPlanCode(batchPlan.getCurrentBatch()+"/"+batchPlan.getBatchCount());
                }
                batchProductDesign.setState(b.getState());

                batchProductDesign.setPlanDesignWh(b.getPlanDesignWh());

                if (designStage.getStagePlanEndTime() != null) {
                    batchProductDesign.setPlanDesignEndDate(designStage.getStagePlanEndTime());
                }
                if (kickOffStage.getStageStartTime() != null) {
                    batchProductDesign.setActualKickoffStartDate(kickOffStage.getStageStartTime());
                }
                if (batchPlan.getProjectName() != null) {
                    batchProductDesign.setProjectName(batchPlan.getProjectName());
                }
                if (batchPlan.getBatchDeliveryDate() != null) {
                    batchProductDesign.setBatchDeliveryDate(batchPlan.getBatchDeliveryDate());
                }
                if (b.getProductType() != null) {
                    batchProductDesign.setProductType(b.getProductType());
                }

                if (b.getProductCode() != null) {
                    batchProductDesign.setProductCode(b.getProductCode());
                }
                if (b.getBopCode() != null) {
                    batchProductDesign.setBopCode(b.getBopCode());
                }
                if (designStage.getStagePlanStartTime() != null) {
                    batchProductDesign.setPlanDesignStartDate(designStage.getStagePlanStartTime());
                }
                if (batchPlan.getMasterPlanId() != null) {
                    String masterPlanId = batchPlan.getMasterPlanId();
                    MasterPlan masterPlanByIdAndDelete = masterPlanRepository.findMasterPlanByIdAndDelete(masterPlanId, 0);
                    batchProductDesign.setMasterPlanCode(masterPlanByIdAndDelete.getMasterPlanCode());
                }
                if (b.getIsStandard() != null) {
                    batchProductDesign.setIsStandard(b.getIsStandard());
                }
                if (batchPlan.getId() != null) {
                    batchProductDesign.setBatchPlanId(batchPlan.getId());
                }
                return batchProductDesign;
            }
        });
        return map;
    }


    /**
     * 添加BOM图纸和工艺路径
     *
     * @param b
     */
    @Transactional
    @Override
    public void addFileAndBop(BatchProduct b) throws Exception {
        System.out.println("正在添加FileAndBop");
        StandProduct standProduct = standProductRepository.findStandProductByStandTypeCodeAndDelete(b.getStandardProductCode(), 0);

        if (b.getIsStandard() == 1) { // 是标准柜才有东西
//                if (b.getBomId() != null) {

            // BOM解析
            StandFileInfo bomFileInfo = standFileInfoRepository.findStandFileInfoByStandTypeIdAndCategoryAndStatusAndDelete(standProduct.getId(), "BOM", 1, 0);
            if (bomFileInfo == null) {
                throw new BeadminException("未找到启用的BOM文件");
            }
//            productBomOverviewService.analyzeBom(b, bomFileInfo);
//                    productBomOverviewService.addBomByTemplate(b.getId(),);
            productBomOverviewService.analyzeStandBom(b, bomFileInfo);


            // 图纸解析
            System.out.println("图纸code：" + b.getDrawingId());
            List<String> drawList = dictDataService.getDictDataKeyByDictTypeName("图纸类别");
            if (drawList == null) {
                throw new BeadminException("未找到图纸类别的字典");
            }
            for (StandFileInfo drawFileInfo : standFileInfoRepository.findStandFileInfoByStandTypeIdAndCategoryInAndStatusAndDelete(standProduct.getId(), drawList, 1, 0)) {
                ProductDrawingInfo productDrawingInfo = new ProductDrawingInfo();
                productDrawingInfo.setProductCode(b.getProductCode());
                productDrawingInfo.setId(drawFileInfo.getId());
                productDrawingInfo.setDrawingUrl(drawFileInfo.getFileUrl());
                productDrawingInfo.setCategory(drawFileInfo.getCategory());
//                productDrawingInfo.set(drawFileInfo.getFileUrl());
                productDrawingInfo.setDrawingName(drawFileInfo.getFileName());
                productDrawingInfo.setDrawingCode(drawFileInfo.getFileCode());
                productDrawingInfo.setVersion(String.valueOf(drawFileInfo.getVersion()));
//                    productDrawingInfo.setDrawingUrl(standFileInfo.get);
                productDrawingInfoRepository.save(productDrawingInfo);
            }

            // BOP
            b.setBopCode(standProduct.getBopCode());
            b.setIsBomUploaded(1);
            b.setReviewState(1);
            b.setReviewTime(new Date());

        }

}
    // 暂时先不用
    private void copyDrawFileInfo(String productCode, StandFileInfo drawFileInfo) throws Exception {
        // 先获取到StandDrawFileInfo
        String objectName = drawFileInfo.getFileCode() + "+1+" + drawFileInfo.getFileName();
        String drawingBucketName = "drawing";

        // 再上到
        BatchProduct batchProductById = batchProductRepository.findBatchProductByProductCode(productCode);
        //在文件名前加上productId
        //根据当前柜体下的文件类别进行版本递增
        List<ProductDrawingInfo> productDrawingInfos = productDrawingInfoRepository.findProductDrawingInfosByProductCodeAndCategoryAndDelete(productCode,drawFileInfo.getCategory(),0);
        int version;
        if(productDrawingInfos==null) {
            version = 1;
        }else{
            version = productDrawingInfos.size()+1;
            //默认最新上传的图纸生效
            for (ProductDrawingInfo p: productDrawingInfos) {
                p.setIsActive(0);
                productDrawingInfoRepository.save(p);
            }
        }

        ProductDrawingInfo productDrawingInfo = new ProductDrawingInfo();
        String fileName = productCode+"-"+version+"-"+drawFileInfo.getFileName();
        //生成图纸code,改成非标的code
        String projectCode = batchProductById.getProductCode().substring(0,batchProductById.getProductCode().indexOf("."));

        int i = productDrawingInfoRepository.countProductDrawingInfoByProductCodeAndDelete(batchProductById.getProductCode(), 0);
        productDrawingInfo.setDrawingCode(projectCode+"."+"003."+String.format("%03d",i+1));
        productDrawingInfo.setProductCode(productCode);
//        productDrawingInfo.setDrawingSpec("drawingSpec");
        //productDrawingInfo.setDrawingUrl(fileName);
        productDrawingInfo.setDrawingName(fileName);
        productDrawingInfo.setCategory(drawFileInfo.getCategory());
        productDrawingInfo.setVersion(String.valueOf(version));
        productDrawingInfo.setIsActive(1);

//        productDrawingInfoRepository.save(productDrawingInfo);



        //批次柜体中修改图纸信息
        batchProductById.setDrawingId(projectCode+"."+"003."+String.format("%03d",i+1));

        batchProductById.setDrawingTime(DateUtil.transDateFormat(new Date()));
        batchProductById.setDrawingIsChange(1);
        //上传到文件系统
        minioUtil.copyObject(drawingBucketName,fileName,drawFileInfo.getBucketName(),objectName);
        String previewFileUrl = minioUtil.getPreviewFileUrl(drawingBucketName, fileName);
//        String previewFileUrl = minioUtil.uploadFile2(multipartFile, fileName, drawingBucketName);
        //String previewFileUrl = minioUtil.getPreviewFileUrl(bucketName, fileName);
        productDrawingInfo.setDrawingUrl(previewFileUrl);
        //添加到数据库
        productDrawingInfoRepository.save(productDrawingInfo);
        //修改批次柜体信息
        batchProductRepository.save(batchProductById);



    }

    /**
     * 柜体设计查询结果
     *
     * @param pageEntity
     * @return
     */
    @Override
    public Page<Object> getBatchProductDesignByPage(PageEntity pageEntity) {
        Page<BatchProductEx> page = batchProductService.getBatchProductByPage(pageEntity);
        Page<Object> page1 = page.map(new Function<BatchProductEx, Object>() {
            @Override
            public Object apply(BatchProductEx dto) {
                BatchPlan batchPlan = batchPlanRepository.findBatchPlanByIdAndDelete(dto.getBatchPlanId(), 0);
                MasterPlan masterPlan = masterPlanRepository.findMasterPlanByIdAndDelete(batchPlan.getMasterPlanId(), 0);
                ProductDesignEx productDesignEx = new ProductDesignEx();
                productDesignEx.setMasterPlanCode(masterPlan.getMasterPlanCode()); //主计划
                if (dto.getId() != null) {
                    productDesignEx.setBatchProductId(dto.getId());
                }
                if (dto.getSerialNo() != null) {
                    productDesignEx.setSerialNo(dto.getSerialNo());
                }
                if (dto.getInfoId() != null) {
                    productDesignEx.setInfoId(dto.getInfoId());
                }
                if (dto.getProjectName() != null) {
                    productDesignEx.setProjectName(dto.getProjectName());
                }
                if (dto.getBatchPlanId() != null) {
                    productDesignEx.setBatchPlanId(dto.getBatchPlanId());
                }
                if (batchPlan.getCurrentBatch() != null && batchPlan.getBatchCount()!=null) {
                    productDesignEx.setBatchPlanCode(batchPlan.getCurrentBatch()+"/"+batchPlan.getBatchCount());
                }
                if (dto.getBatchDeliveryDate() != null) {
                    productDesignEx.setBatchDeliveryDate(dto.getBatchDeliveryDate());
                }
                if (dto.getState() != null) {
                    productDesignEx.setState(dto.getState());
                }
                if (dto.getIsStandard() != null) {
                    productDesignEx.setIsStandard(dto.getIsStandard());
                }
                if (dto.getStandardProductCode() != null) {
                    productDesignEx.setStandardProductCode(dto.getStandardProductCode());
                }
                if (dto.getProductType() != null) {
                    productDesignEx.setProductType(dto.getProductType());
                }
                if (dto.getUnstandardName() != null) {
                    productDesignEx.setUnstandardName(dto.getUnstandardName());
                }
                if (dto.getProductCode() != null) {
                    productDesignEx.setProductCode(dto.getProductCode());
                }
                if (dto.getDesighWhLevel() != null) {
                    productDesignEx.setDesighWhLevel(dto.getDesighWhLevel());
                }
                if (dto.getPlanDesignWh() != null) {
                    productDesignEx.setPlanDesignWh(dto.getPlanDesignWh());
                }
                if (dto.getActualDesignWh() != null) {
                    productDesignEx.setActualDesignWh(dto.getActualDesignWh());
                }
                if (dto.getManufactWhLevel() != null) {
                    productDesignEx.setManufactWhLevel(dto.getManufactWhLevel());
                }
                if (dto.getPlanManufactWh() != null) {
                    productDesignEx.setPlanManufactWh(dto.getPlanManufactWh());
                }
                if (dto.getActualManufactWh() != null) {
                    productDesignEx.setActualManufactWh(dto.getActualManufactWh());
                }
                if (dto.getIsBomUploaded() != null) {
                    productDesignEx.setIsBomUploaded(dto.getIsBomUploaded());
                }
                if (dto.getBomId() != null) {
                    productDesignEx.setBomId(dto.getBomId());
                }
                if (dto.getBomTime() != null) {
                    productDesignEx.setBomTime(dto.getBomTime());
                }
                if (dto.getIsDrawingUploaded() != null) {
                    productDesignEx.setIsDrawingUploaded(dto.getIsDrawingUploaded());
                }
                if (dto.getDrawingId() != null) {
                    productDesignEx.setDrawingId(dto.getDrawingId());
                }
                if (dto.getDrawingTime() != null) {
                    productDesignEx.setDrawingTime(dto.getDrawingTime());
                }
                if (dto.getIsDesignBop() != null) {
                    productDesignEx.setIsDesignBop(dto.getIsDesignBop());
                }
                if (dto.getBopCode() != null) {
                    productDesignEx.setBopCode(dto.getBopCode());
                }
                if (dto.getBopTime() != null) {
                    productDesignEx.setBopTime(dto.getBopTime());
                }
                if (dto.getFileId() != null) {
                    productDesignEx.setFileId(dto.getFileId());
                }
                if (dto.getReviewState() != null) {
                    productDesignEx.setReviewState(dto.getReviewState());
                }
                if (dto.getReviewMemo() != null) {
                    productDesignEx.setReviewMemo(dto.getReviewMemo());
                }
                if (dto.getReviewEditor() != null) {
                    productDesignEx.setReviewEditor(dto.getReviewEditor());
                }
                if (dto.getReviewTime() != null) {
                    productDesignEx.setReviewTime(dto.getReviewTime());
                }
                if (dto.getReviewFileId() != null) {
                    productDesignEx.setReviewFileId(dto.getReviewFileId());
                }
                if (dto.getIsPoReleased() != null) {
                    productDesignEx.setIsPoReleased(dto.getIsPoReleased());
                }
                if (dto.getPoId() != null) {
                    productDesignEx.setPoId(dto.getPoId());
                }
                if (dto.getPoTime() != null) {
                    productDesignEx.setPoTime(dto.getPoTime());
                }
                if (dto.getIsWoReleased() != null) {
                    productDesignEx.setIsWoReleased(dto.getIsWoReleased());
                }
                if (dto.getWoId() != null) {
                    productDesignEx.setWoId(dto.getWoId());
                }
                if (dto.getWoTime() != null) {
                    productDesignEx.setWoTime(dto.getWoTime());
                }
                return productDesignEx;
            }
        });

        return page1;
    }

}